﻿@using eCollabro.Client.Models;
@using eCollabro.Client.Models.Core;
@using eCollabro.Common;
@using eCollabro.Web.Base;
@model NavigationModel
@if (!Request.IsAjaxRequest())
{
    @Scripts.Render("~/bundles/navigation")
}
@{
    List<PermissionEnum> userPermissions = (List<PermissionEnum>)ViewBag.UserPermissions;
    bool canEdit = userPermissions.Contains(PermissionEnum.EditContent);
    bool canDelete = userPermissions.Contains(PermissionEnum.DeleteContent);
    bool canAdd = userPermissions.Contains(PermissionEnum.AddContent);
    List<PageButton> pageButtons = new List<PageButton>();
    pageButtons.Add(new PageButton { Id="btnCancel", CssClass = "btn btn-default", Icon = "remove-circle", ButtonText = "Cancel", Method = "cancel()" });
    if((Model.NavigationId == 0 && canAdd) || (Model.NavigationId != 0 && canEdit))
    {
        pageButtons.Add(new PageButton { Id = "btnSave", ButtonText = "Save",  Icon = "floppy-disk", Method = "saveNavigation()" });
    }
}
<div id="divNavigation" ng-controller="navigationController" ng-init="loadNavigation(@Model.NavigationId)">
    @Html.Partial("_PageHeader", new PageHeaderModel { ViewId = "Navigation", PageTitle = "Navigation - Add/Edit", ValidateForm = true, PageButtons=pageButtons })
    @using (Html.BeginForm("Navigation", "security", FormMethod.Post, new { role = "form", id = "frmNavigation", @class = "form-horizontal" }))
    {
        <div class="row">
            <div class="col-md-6">
                @Html.AntiForgeryToken()
                @if (Model.NavigationId != 0) // Edit Mode
                {
                    <div class="form-group">
                        @Html.LabelFor(m => m.NavigationCode, new { @class = "col-md-4 control-label" })
                        <div class="col-md-8">
                            @Html.TextBoxFor(m => m.NavigationCode, new { ng_model = "navigation.NavigationCode", @readonly = "readonly", @class = "form-control" })
                        </div>
                    </div>
                }
                <div class="form-group">
                    @Html.LabelFor(m => m.NavigationText, new { @class = "col-md-4 control-label" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(m => m.NavigationText, new { ng_model = "navigation.NavigationText", @class = "form-control", maxlength = "255" })
                        @Html.ValidationMessageFor(m => m.NavigationText)
                    </div>
                </div>
                <div class="form-group">
                    @Html.LabelFor(m => m.AdditionalHtml, new { @class = "col-md-4 control-label" })
                    <div class="col-md-8">
                        @Html.TextAreaFor(m => m.AdditionalHtml, new { ng_model = "navigation.AdditionalHtml", @class = "form-control", maxlength = "255" })
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    @Html.LabelFor(m => m.NavigationParentId, new { @class = "col-md-4 control-label" })
                    <div class="col-md-8">
                        <select data-ng-model="selectedParentNavigation" ng-options="parentNavigation.NavigationText for parentNavigation in parentNavigations" class="form-control" ng-change="updateParentNavigation()">
                            <option value="">- Select -</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    @Html.LabelFor(m => m.NavigationTypeId, new { @class = "col-md-4 control-label" })
                    <div class="col-md-8">
                        <select data-ng-model="selectedNavigationType" ng-options="navigationType.NavigationType for navigationType in navigationTypes" class="form-control" ng-change="updateNavigationType()"></select>
                    </div>
                </div>

                <div class="form-group" ng-show="selectedNavigationType.NavigationTypeCode =='NAVTYP0004'">
                    @Html.LabelFor(m => m.Link, new { @class = "col-md-4 control-label" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(m => m.Link, new { ng_model = "navigation.Link", @class = "form-control", maxlength = "255" })
                        @Html.ValidationMessageFor(m => m.Link)
                    </div>
                </div>
                <div class="form-group" ng-show="selectedNavigationType.NavigationTypeCode =='NAVTYP0002'">
                    @Html.LabelFor(m => m.ContentPageId, new { @class = "col-md-4 control-label" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(m => m.ContentPageId, new { ng_model = "navigation.ContentPageId", @class = "form-control", maxlength = "10" })
                        @Html.ValidationMessageFor(m => m.ContentPageId)
                    </div>
                </div>
                <div class="form-group" ng-show="selectedNavigationType.NavigationTypeCode =='NAVTYP0003'">
                    @Html.LabelFor(m => m.FeatureId, new { @class = "col-md-4 control-label" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(m => m.FeatureId, new { ng_model = "navigation.FeatureId", @class = "form-control", maxlength = "10" })
                        @Html.ValidationMessageFor(m => m.FeatureId)
                    </div>
                </div>
                <div class="form-group">
                    @Html.LabelFor(m => m.DisplayOrder, new { @class = "col-md-4 control-label" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(m => m.DisplayOrder, new { ng_model = "navigation.DisplayOrder", @class = "form-control", maxlength = "10" })
                        @Html.ValidationMessageFor(m => m.DisplayOrder)
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-2"></div>
            <label class="checkbox-inline">
                @Html.CheckBoxFor(m => m.IsActive, new { ng_model = "navigation.IsActive" }) @Html.LabelFor(m => m.IsActive)
            </label>
            <label class="checkbox-inline">
                @Html.CheckBoxFor(m => m.IsAnomynousAccess, new { ng_model = "navigation.IsAnomynousAccess" }) @Html.LabelFor(m => m.IsAnomynousAccess)
            </label>
        </div>

        <div class="form-group">
            <div class="col-md-10">
                @Html.Partial("_PageFooter", new PageFooterModel { PageButtons = pageButtons })
            </div>
        </div>

    }
</div>
